package com.hspedu.codeblock;

/**
 * @Author Stringzhua
 * @Date 2024/3/5 16:17
 * description:
 */
public class CodeBlock01 {
    public static void main(String[] args) {
        Movie movie1 = new Movie("热辣滚烫");
        System.out.println("======================");
        Movie movie2 = new Movie("唐人街探案", 40, "小陈思成");
    }
}

class Movie {
    private String name;
    private double price;
    private String director;


    //3个构造器构成了重载关系
    //(1).下面的三个构造器都有相同的语句
    //(2).这样代码看起来比较冗余
    //(3).这时我们可以把相同的语句,放入到一个代码块中即可
    //(4).这样当我们不管调用哪个构造器,都会先调用构造器
    //(5).代码块调用的顺序优先于构造器
    static {
        System.out.println("电影屏幕打开...");
        System.out.println("广告开始...");
        System.out.println("电影正式开始开始...");
    };

    public Movie(String name) {
//        System.out.println("电影屏幕打开...");
//        System.out.println("广告开始...");
//        System.out.println("电影正式开始开始...");
        System.out.println("Movie(String name)构造器被调用~~~");
        this.name = name;
    }

    public Movie(String name, double price) {
//        System.out.println("电影屏幕打开...");
//        System.out.println("广告开始...");
//        System.out.println("电影正式开始开始...");
        this.name = name;
        this.price = price;
    }

    public Movie(String name, double price, String director) {
//        System.out.println("电影屏幕打开...");
//        System.out.println("广告开始...");
//        System.out.println("电影正式开始开始...");
        System.out.println("Movie(String name, double price, String director) 构造器被调用~~~");
        this.name = name;
        this.price = price;
        this.director = director;
    }
}